<script setup lang="ts">
defineProps<{
  list: { id: number; name: string; price: number; num: number }[]
}>()
const emits = defineEmits<{
  (e: 'setNum', x: { id: number; value: 1 | -1 }): void
}>()
</script>

<template>
  <div class="list-page">
    <div class="item">
      <div class="name">商品名</div>
      <div class="price">单价</div>
      <div class="num">数量</div>
    </div>
    <div class="item" v-for="(item, index) in list" :key="index">
      <div class="name">{{ item.name }}</div>
      <div class="price">{{ item.price }}</div>
      <div class="num">
        <button @click="emits('setNum', { id: item.id, value: 1 })">+</button>
        {{ item.num }}
        <button @click="emits('setNum', { id: item.id, value: -1 })">-</button>
      </div>
    </div>
  </div>
</template>

<style scoped>
.item {
  display: flex;
  justify-content: space-between;
}
</style>
